﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
using DecisionFramework.Logging.Internal;
using DecisionFramework.Instrument;


namespace DecisionFramework.Logging
{
    /// <summary>
    /// Provides an implementation of IReportProvider that
    /// reports the instrumentation to a ILogService. 
    /// </summary> 
    /// Author: Greg Cowin
    /// </remarks>
	public class LogServiceReportProvider : IReportProvider
	{
        /// <summary>
        /// The component name that the instrumentation is associated with.
        /// </summary>
		public string ComponentName  {get; set;}

        /// <summary>
        /// Provides an implementation of IReportInstrumentation that
        /// reports the instrumentation to a ILogService. 
        /// </summary>
        /// <param name="instrumentation">The instrumentation to report.</param>
		public void Report(Instrumentation instrumentation)
		{
            if (ComponentName == null) ComponentName = instrumentation.Name + ".Instrumentation";

            ILogService service = new EventViewerLogService();
			service.Operational[ComponentName].WriteAppEvent(new AppEvent
			{
				WhatHappened = "Reporting Instrumentation",
				WhyDidItHappen = "The following Instrumentation reporting policy determined that it was time to report: " 
                    + instrumentation.PublishPolicy.ToString(),
				Details = instrumentation.ToString()
			});   
		}
	}
}
